package com.it;

import com.it.bean.R;
import com.it.bean.RestStatusEnum;
import com.it.pojo.params.product.ProductQuery;
import com.it.pojo.params.product.ProductSearchQuery;
import com.it.pojo.vo.product.ProductTicketVO;
import com.it.pojo.vo.product.ProductTypeVO;
import com.it.pojo.vo.product.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("product")
@Api(value = "v2", tags = "漫展相关接口")

public class ProductController {

    @Resource
    private ProductService productService;

    @PostMapping("")
    @ApiOperation(value = "查询所有漫展信息", notes = "查询所有漫展信息")
    public R<?> list(@RequestBody ProductQuery productQuery) {
        if (productQuery == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        System.out.println("productQuery = " + productQuery);
        String time = productQuery.getTime();
        System.out.println(time.equals(""));
        List<ProductVO> productVOS = productService.listProductVO(productQuery);
        return R.success("成功", productVOS);
    }
    @PostMapping("search")
    @ApiOperation(value = "根据关键字搜索漫展信息", notes = "根据关键字搜索漫展信息")
    public R<?> listSearch(@RequestBody ProductSearchQuery productSearchQuery) {
        if (productSearchQuery == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        System.out.println("productQuery = " + productSearchQuery);
        Map<String, Object> map = productService.listProductVOByKeyWords(productSearchQuery);
        return R.success("成功", map);
    }

    @GetMapping("{productid}")
    @ApiOperation(value = "根据漫展id查询漫展详情信息", notes = "根据漫展id查询漫展详情信息")

    public R<?> listproductsById(@PathVariable("productid") Integer productId) {
        if (productId == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        Map<String, Object> map = productService.listproductsById(productId);
        return R.success("成功", map);
    }

    @GetMapping("/name/{productid}")
    @ApiOperation(value = "根据漫展id获取漫展名称", notes = "根据漫展id获取漫展名称")

    public R<?> getProductNameById(@PathVariable("productid") Integer productId) {
        if (productId == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        String productName = productService.getProductNameById(productId);
        return productName != null ? R.success("成功", productName) : R.error();
    }


    @GetMapping("/ticket/{productid}")
    @ApiOperation(value = "根据漫展id查询购票相关信息", notes = "根据漫展id查询购票相关信息")
    public R<?> getProductTicketInfo(@PathVariable("productid") Integer productId) {
        if (productId == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        ProductTicketVO productTicketVO = productService.getProductTicketInfo(productId);
        return R.success("成功", productTicketVO);
    }


    @GetMapping("/type")
    @ApiOperation(value = "查询周边商品相关信息", notes = "查询周边商品相关信息")
    public R<?> listProductTypeVO(@RequestParam("typeId") Integer typeId
            , @RequestParam("condtion") Integer condtion,@RequestParam("keyWords") String keyWords) {
        System.out.println("typeId = " + typeId);
        System.out.println("condtion = " + condtion);
        System.out.println("keyWords = " + keyWords);
        Map<String, Object> map = productService.listProductTypeVO(typeId, condtion,keyWords);
        return R.success("成功", map);
    }

    @GetMapping("/type/{productId}")
    @ApiOperation(value = "查询周边商品详情信息", notes = "查询周边商品详情信息")
    public R<?> listProductTypeVOById(@PathVariable("productId") Integer productId) {
        if (productId == null) {
            return R.error(RestStatusEnum.PARAMS_ERROR);
        }
        ProductTypeVO productTypeVO = productService.listProductTypeVOById(productId);
        return R.success("成功", productTypeVO);
    }
}